home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / comm / tcp / FtpDaemon.lha / amimsg / amimsg.c < prev   
C/C++ Source or Header  |  1993-10-29  |  2KB  |  93 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <netdb.h>
  5. #include <sys/types.h>
  6. #include <netinet/in.h>
  7. #include <libraries/multiuser.h>
  8.  
  9. #include <proto/dos.h>
  10. #include <proto/exec.h>
  11. #include <proto/multiuser.h>
  12.  
  13. struct muBase *muBase;
  14.  
  15. long gethostname(char *,long len);
  16.  
  17. char CommandTemplate[]="MSG/A,TO/K,NAME=FROM/K";
  18. LONG CommandResults[]={NULL,(LONG)"localhost",(LONG)"root"};
  19. char hostname[30];
  20. char Buffer[512];
  21.  
  22. void main(void)
  23. {
  24.     struct RDArgs *CommandRDArgs;
  25.     struct sockaddr_in server;
  26.     struct servent *sp;
  27.     struct hostent *hp;
  28.     char UserName[muUSERIDSIZE]="";
  29.     long s;
  30.     
  31.     if((CommandRDArgs=ReadArgs(CommandTemplate,CommandResults,NULL)))
  32.     {
  33.         muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
  34.         if(muBase)
  35.         {
  36.             struct muUserInfo *UserInfo;
  37.             
  38.             if(UserInfo=muAllocUserInfo())
  39.             {
  40.                 UserInfo->uid=(muGetTaskOwner(NULL)&muMASK_UID)>>16;
  41.                 if(muGetUserInfo(UserInfo,muKeyType_uid))
  42.                 {
  43.                     strcpy(UserName,UserInfo->UserID);
  44.                     CommandResults[2]=(LONG)UserName;
  45.                 }
  46.                 muFreeUserInfo(UserInfo);
  47.             }
  48.             
  49.             CloseLibrary((struct Library *)muBase);
  50.         }
  51.         
  52.         gethostname(hostname,sizeof(hostname));
  53.         sp=getservbyname("amimsg","tcp");
  54.         if(sp==NULL)
  55.             fprintf(stderr,"amimsg: tcp/amimsg: unknown service\n");
  56.         else
  57.         {
  58.             hp=gethostbyname((char *)CommandResults[1]);
  59.             if(hp==NULL)
  60.                 fprintf(stderr,"amimsg: %s unknown host\n",CommandResults[1]);
  61.             else
  62.             {
  63.                 bzero((char *)&server,sizeof(server));
  64.                 server.sin_port=sp->s_port;
  65.                 bcopy(hp->h_addr,(char *)&server.sin_addr,hp->h_length);
  66.                 server.sin_family=hp->h_addrtype;
  67.                 s=socket(AF_INET,SOCK_STREAM,0);
  68.                 if(s<0)
  69.                     perror("amimsg: socket");
  70.                 else
  71.                 {
  72.                     if(connect(s,(struct sockaddr *)&server,sizeof(server))<0)
  73.                         perror("amimsg: connect");
  74.                     else
  75.                     {
  76.                         sprintf(Buffer,
  77.                             "HOST %s\n"
  78.                             "USER %s\n"
  79.                             "MSG %s\n",
  80.                             hostname,
  81.                             CommandResults[2],
  82.                             CommandResults[0]
  83.                         );
  84.                         send(s,Buffer,strlen(Buffer),0);
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.         FreeArgs(CommandRDArgs);
  90.     }
  91.     else fprintf(stderr,"bad args.\n");
  92. }
  93.